{include file="public_head"}
<style>
  #sub{
    width: 250px;
    line-height: 48px;
    font-size: 18px;
    background: #E43C3F;
    border: none;
    outline: none;
    border-radius: 6px;
    margin: 50px auto 0;
    display: block;
    color: white;
  }
</style>
  <div class="content_center">
    <div class="main_center">

      <!--菜单-->
      <div class="main_left left">
        {include file="public_information_menu"}
      </div>
      <!--菜单-->

      <div class="main_right right">
        <div class="main_right_title">佣金<span class="right"></span></div>
        <div class="integral_con">
          <div class="center-cash">

            <!--余额-->
            <div class="balance">
              <div class="main">
                <div class="left">
                  <img class="qianbi" src="__STATIC__/img/logo25.jpg">
                  <span class="yue">余额（元）</span>
                  <h4 class="price">{$find.balance}元</h4>
                </div>
              </div>
            </div>
            <!--余额-->


            <div class="cash">

              <!--充值金额-->
              <div>
                <h4>充值金额</h4>
                <input type="text" placeholder="充值金额需大于1.00元" class="text" name="price" id="price">
              </div>
              <!--充值金额-->

              <!--充值方式-->
              <div>
                <h4>充值方式</h4>
                <form role="form">
                  <div class="form-group">
                    <select class="form-control" name="way" id="way">
                      <option value="1">支付宝</option>
                      <option value="2">微信</option>
                    </select>
                  </div>
                </form>
              </div>
              <!--充值方式-->

              <input type="submit" onclick="rechage()"  id="sub">
            </div>

          </div>
        </div>
      </div>
    </div>
  </div>
<div id="alipay" hidden></div>
<script>
  // 充值
  function rechage() {

    // 金额
    var price = $("#price").val();

    // 判断充值金额
    var zz = /^-?\d+\.?\d{0,2}$/;
    if (! zz.test(price)) {
      layer.msg('充值金额有误！');
      return;
    }

    // 方式
    var way = $("#way").val();

    $.ajax({
      url: "{:url('shop/recharge/index')}",
      dataType: 'json',
      type: 'post',
      data: {'price': price, 'way': way},
      success: function (t) {
        if (t.code == 200) {
          if (way==1) {
            var body1 = 'recharge|'+t.user_id;
            console.log(t);
            callpay_al(body1,t.order_number,t.price);

          }else if (way==2){
            var body = 'recharge|'+t.user_id;
            location.href = "{:url('shop/WeChat/rechange')}?order_number="+t.order_number+"&body="+body+'&price='+t.price;
          }

        } else {
          layer.msg(t.message);
        }

      }
    })
  }


  function callpay_al(a,b,c) {
    $.ajax({
      url:"{:url('shop/Alipay/rechage')}",
      dataType: 'html',
      type: 'post',
      data:{'order_number':b,'body':a,'price':c},
      success:function (data) {
        $('#alipay').html(data);
      }

    });
  }
</script>
{include file="public_foot"}